# -*- coding: utf-8 -*-
# @Time : 2024/2/18 9:22
# @Author : ZH
# @File : 589.py
# @Software: PyCharm
# Definition for a Node.
from typing import List


class Node:
    def __init__(self, val=None, children=None):
        self.val = val
        self.children = children


class Solution:
    def preorder(self, root: 'Node') -> List[int]:
        ans = []

        def dfs(node: 'Node'):
            if node is None:
                return
            ans.append(node.val)
            for ch in node.children:
                dfs(ch)

        dfs(root)
        return ans

